package top.xylweb.attend.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xylweb.attend.entity.Attend;
import top.xylweb.attend.service.AttendServiceInter;
import top.xylweb.attend.vo.QueryCondition;
import top.xylweb.common.page.PageQueryBean;
import top.xylweb.user.entity.User;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("attend")
public class AttendController {

    @Autowired
    private AttendServiceInter attendServiceInter;

    @RequestMapping
    public String attendPage(){
        return "attend";
    }

    /**
     * @Author X [**.**.**]
     * @Date 2017/12/18 19:19
     * Description  模拟添加 签到
     **/
    @RequestMapping("/signAttend")
    @ResponseBody
    public String signAttend(@RequestBody Attend attend) throws Exception {
        attendServiceInter.signAttend(attend);
        return "succ";
    }

    /**
     * @Author X [**.**.**]
     * @Date 2018/1/6 15:40
     * Description 考勤分页查询
     **/
    @RequiresPermissions("attend:attendList")

    @RequestMapping("/attendList")
    @ResponseBody
    public PageQueryBean listAttend(QueryCondition condition,HttpSession session){
        User user = (User) session.getAttribute("userinfo");
        String [] rangeDate = condition.getRangeDate().split("/");
        condition.setStartDate(rangeDate[0]);
        condition.setEndDate(rangeDate[1]);
        condition.setUserId(user.getId());
        PageQueryBean result = attendServiceInter.listAttend(condition);
        return result;
    }
}
